package com.briup.mt.service.impl;

import com.briup.mt.bean.Interfaces;
import com.briup.mt.bean.InterfacesExample;
import com.briup.mt.dao.InterfacesMapper;
import com.briup.mt.service.IInterfacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wyq
 * @create 2020-12-16 14:46
 */


@Service
public class InterfacesServiceImpl implements IInterfacesService {
    @Autowired
    private InterfacesMapper interfacesMapper;

    @Override
    public List<Interfaces> query(String name) {
        InterfacesExample example = new InterfacesExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%" + name + "%");
        }
        List<Interfaces> list = interfacesMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Interfaces interfaces) {
        if (interfaces.getId() == null) {
            interfacesMapper.insert(interfaces);
        } else {
            interfacesMapper.updateByPrimaryKey(interfaces);
        }
    }

    @Override
    public void deleteById(long id) {
        interfacesMapper.deleteByPrimaryKey(id);
    }
}
